package com.aizuda.boot.modules.third.wps.domain.vo;

import cn.hutool.core.util.StrUtil;
import com.aizuda.boot.modules.third.wps.enums.WebOfficeErrEnum;
import com.aizuda.core.api.ApiResult;
import com.aizuda.service.anno.LongToStringIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @author hjw
 * @description WPS返回对象
 * @date 2025年06月13日 16:15
 */
@Schema
@AllArgsConstructor
@Accessors(chain = true)
@Data
public class ResponseDTO<T> extends ApiResult<T> {

    public static final int SUCCESS_CODE = 0;

    @Schema(description = "返回码")
    @LongToStringIgnore
    private long code;

    @Schema(description = "返回消息")
    private String message;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    @Schema(description = "返回数据")
    private T data;


    public static <T> ResponseDTO<T> success(T data) {
        return result(SUCCESS_CODE, "", data);
    }

    public static <T> ResponseDTO<T> result(Integer code, String message, T data) {
        return new ResponseDTO<>(code, message, data);
    }

    public static <T> ResponseDTO<T> error(WebOfficeErrEnum errorEnum, String msg) {
        return new ResponseDTO<>(errorEnum.getCode(),
                StrUtil.isBlank(msg) ? errorEnum.getMsg() : msg,
                null);
    }

    public static <T> ResponseDTO<T> error(WebOfficeErrEnum errorEnum) {
        return new ResponseDTO<>(errorEnum.getCode(),
                errorEnum.getMsg(),
                null);
    }

}
